/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CatForm.java
 *
 * Created on 02-may-2011, 13:02:55
 */
package es.fpsampayo.fin2006.gui.forms;

import es.fpsampayo.fin2006.gui.paneles.Finca;
import es.fpsampayo.fin2006.gui.paneles.ListadoConstrucciones;
import es.fpsampayo.fin2006.gui.paneles.ListadoUnidadesConstructivas;
import javax.swing.JFrame;

/**
 *
 * @author fran
 */
public class CatForm extends javax.swing.JDialog {
    
    
    
    private int id;
    Finca finca;
    ListadoUnidadesConstructivas unidades;
    ListadoConstrucciones cons;
    String titulo = "Finca";

    private CatForm(JFrame jFrame, boolean b) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    /** Creates new form CatForm */
    public CatForm(java.awt.Frame parent, boolean modal, int id) {
        super(parent, modal);
        this.id = id;
        this.setAlwaysOnTop(false);
        
        initComponents();
        finca = new Finca();
        finca.cargarCampos(id);
        jTabbedPane1.addTab("Finca", finca);
        
        unidades = new ListadoUnidadesConstructivas();
        unidades.cargarUnidades(id);
        jTabbedPane1.addTab("Unidades Constructivas", unidades);
        
        cons = new ListadoConstrucciones();
        cons.cargarConstrucciones(id);
        jTabbedPane1.addTab("Construcciones", cons);
        
        setTitulo();
        
    }
    
    public final void setTitulo (){
        this.setTitle("Finca - " + finca.getReferencia_catastral());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnAnterior = new javax.swing.JButton();
        btnAceptar = new javax.swing.JButton();
        btnSiguiente = new javax.swing.JButton();
        jTabbedPane1 = new javax.swing.JTabbedPane();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(670, 580));
        setResizable(false);

        btnAnterior.setText("Anterior");
        btnAnterior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAnteriorActionPerformed(evt);
            }
        });

        btnAceptar.setText("Aceptar");
        btnAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAceptarActionPerformed(evt);
            }
        });

        btnSiguiente.setText("Siguiente");
        btnSiguiente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSiguienteActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(439, Short.MAX_VALUE)
                .addComponent(btnAnterior)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnSiguiente)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnAceptar)
                .addContainerGap())
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 680, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 488, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 13, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAceptar)
                    .addComponent(btnSiguiente)
                    .addComponent(btnAnterior))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnAnteriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAnteriorActionPerformed
        // TODO add your handling code here:
        id = id - 1;
        finca.cargarCampos(id);
        unidades.cargarUnidades(id);
        cons.cargarConstrucciones(id);
        setTitulo();
        
}//GEN-LAST:event_btnAnteriorActionPerformed

    private void btnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAceptarActionPerformed
        // TODO add your handling code here:
        this.dispose();
}//GEN-LAST:event_btnAceptarActionPerformed

    private void btnSiguienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSiguienteActionPerformed
        // TODO add your handling code here:
        id = id + 1;
        finca.cargarCampos(id);
        unidades.cargarUnidades(id);
        cons.cargarConstrucciones(id);
        setTitulo();
}//GEN-LAST:event_btnSiguienteActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                CatForm dialog = new CatForm(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAceptar;
    private javax.swing.JButton btnAnterior;
    private javax.swing.JButton btnSiguiente;
    private javax.swing.JTabbedPane jTabbedPane1;
    // End of variables declaration//GEN-END:variables
}
